package com.hnchances.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hnchances.context.BaseContext;
import com.hnchances.mapper.*;
import com.hnchances.pojo.PageResult;
import com.hnchances.pojo.dto.GradesDTO;
import com.hnchances.pojo.dto.GradesPageDTO;
import com.hnchances.pojo.entity.Exam;
import com.hnchances.pojo.entity.Grades;
import com.hnchances.pojo.entity.User;
import com.hnchances.service.GradesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradesServiceImpl implements GradesService {

    private final UserMapper userMapper;

    private final GradesMapper gradesMapper;

    public GradesServiceImpl(GradesMapper gradesMapper, UserMapper userMapper) {
        this.gradesMapper = gradesMapper;
        this.userMapper = userMapper;
    }

    @Override
    public void add(GradesDTO gradesDTO) {
        // 给学生添加成绩
        gradesMapper.add(gradesDTO);

    }

    @Override
    public void del(Integer id) {
        // 更改状态
        Grades grades = gradesMapper.selectById(id);
        grades.setStatus(1);
        gradesMapper.update(grades);
    }

    @Override
    public PageResult page(GradesPageDTO gradesPageDTO) {
        PageHelper.startPage(gradesPageDTO.getPage(), gradesPageDTO.getSize());
        List<Grades> list = gradesMapper.pageQuery(gradesPageDTO);
        Page<Grades> page = (Page<Grades>) list;
        return new PageResult(page.getTotal(), page.getResult());
    }

}
